import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

import d1 from '@/views/d1.vue'
import d2 from '@/views/d2.vue'
import d3 from '@/views/d3.vue'
import d4 from '@/views/d4.vue'
import d5 from '@/views/d5.vue'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/xxxx',
    name: 'xxxx',
    component: () => import('../views/xxxx.vue'),
    children:[
      {
        path: 'd1',
        name: 'd1',
        component:d1
      },
      {
        path: 'd2',
        name: 'd2',
        component:d2
      },
      {
        path: 'd3',
        name: 'd3',
        component:d3
      },
      {
        path: 'd4',
        name: 'd4',
        component:d4
      },
      {
        path: 'd5',
        name: 'd5',
        component:d5
      },
    ]
  }
]

const router = new VueRouter({
  routes
})


router.beforeEach((to,from,next)=>{
  if (to.path!='/xxxx') {
    var token=localStorage.getItem('token')
    if (token) {
      next()
    }else{
      next('/xxxx')
    }
  }else{
    next()
  }
})
export default router
